package com.vancouver.knows.ui.activity.userpost;

import android.content.Context;
import android.view.View;

import com.pangu.ui.refresh.ARefreshViewController;
import com.pangu.ui.refresh.RefreshControllerView;
import com.vancouver.knows.MainApplication;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.bean.UserPostInfo;
import com.vancouver.knows.business.task.mark.GetUserPostsTaskMark;

/**
 * Created by Chris Li on 2016-07-23.
 */
public class UserPostListsPullRefreshView extends RefreshControllerView {

    public UserPostListsPullRefreshView(Context context) {
        super(context);
    }

    private UserPostListsView mUserPostsListView;

    @Override
    protected View createContentView() {
        mUserPostsListView = new UserPostListsView(getContext(), this);
        return mUserPostsListView;
    }

    @Override
    public void onRefresh(ARefreshViewController controller) {
        ((UserPostListsView) content).handleRefreshLoadItem();
    }

    public void loadData(String page, String userId, String status) {
        BusinessModule module = ((MainApplication) imContext).getBusinessModule();
        GetUserPostsTaskMark getUserPostsTaskMark;
        if (status.equals(UserPostInfo.DRAFT_STATUS)) {
            getUserPostsTaskMark = new GetUserPostsTaskMark(page, userId, status);
        } else {
            getUserPostsTaskMark = module.getTaskMarkPool().getUserPostsTaskMark(page, userId, status);
        }
        ((UserPostListsView) content).initLoadableView(getUserPostsTaskMark);
    }

    public void removeUserPostItem() {
        if (mUserPostsListView != null) {
            mUserPostsListView.removeDraftItem();
        }
    }
}
